<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="https://cdn.tailwindcss.com"></script>
    <link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.7.2/css/all.min.css" rel="stylesheet">
    <title>短信界面</title>
    <style>
        /* iPhone 16 类似边框样式 */
        .iphone-16-frame {
            width: 390px;
            height: 844px;
            background-color: #121212;
            border-radius: 60px;
            box-shadow: 0 0 30px rgba(0, 0, 0, 0.7);
            display: flex;
            justify-content: center;
            align-items: center;
            position: relative;
            overflow: hidden;
        }

        .dynamic-island {
            width: 120px;
            height: 32px;
            background-color: #000;
            border-radius: 20px;
            position: absolute;
            top: 20px;
            left: 50%;
            transform: translateX(-50%);
        }

        .message-container {
            flex: 1;
            overflow-y: auto;
            padding: 20px;
        }

        .message {
            padding: 8px;
            margin: 4px;
            border-radius: 8px;
        }

        .sent {
            background-color: #DCF8C6;
            align-self: flex-end;
        }

        .received {
            background-color: #E5E5EA;
            align-self: flex-start;
        }

        .screen {
            width: 92%;
            height: 94%;
            background-color: white;
            border-radius: 40px;
            overflow: hidden;
            display: flex;
            flex-direction: column;
        }

        .input-area {
            padding: 15px;
            border-top: 1px solid #e5e5e5;
            display: flex;
            justify-content: space-between;
            align-items: center;
            background-color: white;
        }

        .input-area textarea {
            flex-grow: 1;
            border: 1px solid #ccc;
            border-radius: 8px;
            padding: 10px;
            margin-right: 10px;
            resize: none;
            min-height: 2em;
            max-height: 10em;
        }

        .input-area button {
            background-color: transparent;
            color: #007aff;
            border: none;
            cursor: pointer;
            font-size: 20px;
        }
    </style>
</head>

<body class="bg-gray-100 flex justify-center items-center h-screen">
<div class="iphone-16-frame">
    <div class="dynamic-island"></div>
    <div class="screen">
        <div class="bg-blue-500 text-white p-4">
            <h2 class="text-lg font-bold">短信对话</h2>
        </div>
        <div class="message-container p-4 space-y-2 flex flex-col">
            <!-- 这里会动态添加消息 -->
        </div>
        <div class="input-area">
            <textarea id="message-input" placeholder="输入短信内容"></textarea>
            <button id="send-button">
                <i class="fa-solid fa-paper-plane"></i>
            </button>
        </div>
    </div>
</div>
<script>
    const messageContainer = document.querySelector('.message-container');
    const messageInput = document.getElementById('message-input');
    const sendButton = document.getElementById('send-button');

    function adjustTextareaHeight() {
        messageInput.style.height = 'auto';
        messageInput.style.height = Math.min(messageInput.scrollHeight, 10 * parseFloat(getComputedStyle(messageInput).lineHeight)) + 'px';
    }

    messageInput.addEventListener('input', adjustTextareaHeight);

    messageInput.addEventListener('keydown', (event) => {
        if (event.key === 'Enter' && event.ctrlKey) {
            event.preventDefault();
            const messageText = messageInput.value;
            if (messageText.trim()!== '') {
                const messageElement = document.createElement('div');
                messageElement.classList.add('message','sent');
                messageElement.textContent = messageText;
                messageContainer.appendChild(messageElement);
                messageInput.value = '';
                messageInput.style.height = 'auto';
            }
        } else if (event.key === 'Enter') {
            adjustTextareaHeight();
        }
    });

    sendButton.addEventListener('click', () => {
        const messageText = messageInput.value;
        if (messageText.trim()!== '') {
            const messageElement = document.createElement('div');
            messageElement.classList.add('message','sent');
            messageElement.textContent = messageText;
            messageContainer.appendChild(messageElement);
            messageInput.value = '';
            messageInput.style.height = 'auto';
        }
    });
</script>
</body>

</html>

